﻿/**
 * 门店信息
 */

var littleNav = document.querySelector('.little_nav');
var littleItem = document.querySelectorAll('.little_nav .slider .item');
var littleLength = littleItem.length;
var littleIndex = 0; // 当前索引
var imgs = [
    '../imgs/little_nav.png',
    '../imgs/little_nav2.jpg',
    '../imgs/little_nav3.jpg',
    '../imgs/little_nav4.jpg',
    '../imgs/little_nav5.jpg'
]

/**设置图片导航 */
function setLittleNav(type) {
    if (type === 'open') {
        // 开启
        littleNav.classList.add('show');
    } else {
        // 关闭
        littleNav.classList.remove('show');
    }
}

/**切换图片 */
function activeLittleImg(position) {
    if (position === 'prev') {
        // 上一张
        if (littleIndex <= 0) {
            littleIndex = littleLength - 1;
        } else {
            littleIndex--;
        }
    } else if (position === 'next') {
        // 下一张
        if (littleIndex >= littleLength - 1) {
            littleIndex = 0;
        } else {
            littleIndex++;
        }
    }
    showLittleImg(littleIndex);
};

/**显示指定索引图片 */
function showLittleImg(index) {
    for (var i = 0; i < littleLength; i++) {
        littleItem[i].classList.remove('show');
    };
    littleItem[index].classList.add('show');
    setMainImg(index);
}

/**设置主图 */
function setMainImg(index) {
    var mainImg = document.querySelector('.content-min-img');
    var mainNum = document.querySelector('.content-img-num');
    mainImg.style.backgroundImage = 'url(' + imgs[index] + ')';
    mainNum.innerHTML = index + 1 + ' / ' + imgs.length;
}